package com.woyowodaows.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.woyowodaows.R;
import com.woyowodaows.weight.RatingBar;


/**
 * 两个按钮弹出框
 */

public class ConfirmTwoButtonDialog {

    private Context mContext;
    public Dialog dialog;
    public TextView tvTitles;
    private Button btnSubmit;
    public ImageView ivCancel;
    public  Button btnCancel;
    public EditText etFeedback0pinion;//输入的评价内容
    public RatingBar ratingBar;//评论的分数

    public float evaluationService = 0;

    public ConfirmTwoButtonDialog(Context context) {
        this.mContext = context;
        initDialog();
    }
    public void setTitileName(String titleName){
        if (titleName != null) {
            tvTitles.setText(titleName);
        }
    }
    public String getDataDiscuss(){//评论的数据
         String  Discuss=etFeedback0pinion.getText().toString().trim();
        return Discuss;

    }
    public float getGrade(){//得到分数

             return  evaluationService;
    }

    public void setSubmitText(String submitText){
         if (submitText != null){
             btnSubmit.setText(submitText);
         }
    }

    private void initDialog() {
        dialog = new Dialog(mContext, R.style.dialog);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_two_confirm_button);
        ivCancel = (ImageView) window.findViewById(R.id.iv_cancel);
        btnSubmit = (Button) window.findViewById(R.id.btn_submit);
        tvTitles=(TextView)window.findViewById(R.id.tv_titles);
        btnCancel=(Button)window.findViewById(R.id.btn_cancel);//取消
        etFeedback0pinion=(EditText) window.findViewById(R.id.et_feedback_opinion);//取消
        ratingBar=(RatingBar) window.findViewById(R.id.rb_evaluation_logistics);//取消
        //服务态度评分
        ratingBar.setOnRatingChangeListener(new RatingBar.OnRatingChangeListener() {
            @Override
            public void onRatingChange(float ratingCount) {
                evaluationService = ratingCount;
            }
        });
        ivCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismissDialog();
            }
        });
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sumbitAudit();
            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissDialog();
            }
        });
    }

    private void sumbitAudit() {
        if (onTwoButtonListener != null){
            onTwoButtonListener.onConfirmButton();
        }
        dismissDialog();
    }

    /**
     * 显示dialog
     */
    public void showDialog() {
        if (dialog != null)
            dialog.show();
    }

    /**
     * 关闭dialog
     */
    public void dismissDialog() {
        if (dialog != null)
            dialog.dismiss();
    }

    public interface   OnTwoButtonListener{
        void onConfirmButton();
    }

    private OnTwoButtonListener onTwoButtonListener;

    public void setTwoButtonListener( OnTwoButtonListener onTwoButtonListener) {
        this.onTwoButtonListener = onTwoButtonListener;
    }
}
